// ActionScript file
package com.app.business{
	import com.adobe.cairngorm.business.ServiceLocator;
	import com.app.factories.PesanFactory;
	import com.app.vo.DosenVO;
	import com.app.vo.MahasiswaVO;
	import com.app.vo.PesanVO;
	
	import mx.rpc.IResponder;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.http.HTTPService;
	
    
    public class PesanDelegate implements IResponder{
        protected var responder:IResponder;
        protected var service:HTTPService;
        protected var dosenVo:DosenVO;
        protected var pesanVo:PesanVO;
        protected var mahasiswaVo:MahasiswaVO;
        protected var Param:String;
        protected var Act:String;
        protected var Com:String;
        protected var rs:Array;
        
        public function PesanDelegate(responder:IResponder){
            this.service=ServiceLocator.getInstance().getHTTPService('services');
            this.responder=responder;
            this.rs=new Array();
        }  
        public function getPesanById(psnVo:PesanVO):void{
            this.Param=psnVo.pesanId;
            this.Act="getPesanById";
            this.Com="pesan";
            var token:AsyncToken=service.send({com:Com,act:Act,params:Param});
            token.addResponder(this);
            this.pesanVo=psnVo;
        }
        public function getPesanByPenerima(psnVo:PesanVO):void{
            this.Param=psnVo.pesanPenerima;
            this.Act="getPesanByPenerima";
            this.Com="pesan";
            var token:AsyncToken=service.send({com:Com,act:Act,params:Param});
            token.addResponder(this);
            this.pesanVo=psnVo;
        }
        public function getPesanByPengirim(psnVo:PesanVO):void{
            this.Param=psnVo.pesanPengirim;
            this.Act="getPesanByPengirim";
            this.Com="pesan";
            var token:AsyncToken=service.send({com:Com,act:Act,params:Param});
            token.addResponder(this);
            this.pesanVo=psnVo;
        }
        public function doAddPesan(psnVo:PesanVO):void{
            this.Param=psnVo.getAddParam();
            this.Act="doAddPesan";
            this.Com="pesan";
            var token:AsyncToken=service.send({com:Com,act:Act,params:Param});
            token.addResponder(this);
            this.pesanVo=psnVo;
        }
        public function result(data:Object):void{
            var event:ResultEvent=ResultEvent(data);
            if(event.result!='false'){
                if(this.Act=="getPesanById"){
                    this.pesanVo=PesanFactory.buildPesanById(event.result as String, this.pesanVo);
                    responder.result(this.pengumumanVo);
                }else if(this.Act=="getPesanByPenerima"){
                    this.pesanVo=PesanFactory.buildPesanByPenerima(event.result as String, this.pesanVo)
                    responder.result(this.pengumumanVo);
                }else if(this.Act=="getPesanByPengirim"){
                	this.pesanVo=PesanFactory.buildPesanByPengirim(event.result as String, this.pesanVo)
                    responder.result(this.pengumumanVo);
                }else if(this.Act=="doAddPesan"){
                    responder.result(this.pengumumanVo);
                }
            }else{
                responder.fault(null);
            }
        }
        public function fault(info:Object):void{
            var err:FaultEvent= FaultEvent(info);
        }
    }
}